package com.jiezuo.flowable.listener;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.BaseExecutionListener;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

/**
* @description   执行监听器（sequenceFlow）
* @author        庞留杰
* @date          2020/9/21 10:07
* @version       V1.0
**/
@Slf4j
@Component
public class MyFlowListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution delegateExecution) {
        String processDefinitionId = delegateExecution.getProcessDefinitionId();
        String processInstanceId = delegateExecution.getProcessInstanceId();
        String eventName = delegateExecution.getEventName();
        log.info(">>>>>>>>>>>>>>>> 执行监听器，流程定义ID:{}   流程实例ID:{} >>>>>>>>>>>>>>>>", processDefinitionId, processInstanceId);
        delegateExecution.getCurrentActivityId();
        switch (eventName){
            case BaseExecutionListener.EVENTNAME_START:
                log.info(">>>>>>>>>>>>>>>> 执行监听器，{}事件执行了start >>>>>>>>>>>>>>>>", eventName);break;
            case BaseExecutionListener.EVENTNAME_END:
                log.info(">>>>>>>>>>>>>>>> 执行监听器，{}事件执行了end >>>>>>>>>>>>>>>>", eventName);break;
            case BaseExecutionListener.EVENTNAME_TAKE:
                // 执行后可以添加参数
                // delegateExecution.setVariable("SYSTEM_JUDGE_SUBMIT_VALUE","pass");
                log.info(">>>>>>>>>>>>>>>> 执行监听器，{}事件执行了take >>>>>>>>>>>>>>>>", eventName);break;
            default:
                break;
        }
    }

}
